<template>
  <div class="shop-login">
    <div class="shop-login-from">
       请填写身份信息<br>

      <el-input v-model="from.username" placeholder="请输入用户名"
                style="width: 300px;margin-top: 20px">
        <template #prefix>
          <el-icon class="el-input__icon">
            <Avatar/>
          </el-icon>
        </template>
      </el-input>

      <el-input v-model="from.nickName" placeholder="请输入用户昵称"
                style="width: 300px;margin-top: 20px;">
        <template #prefix>
          <el-icon class="el-input__icon">
            <chat-dot-square />
          </el-icon>
        </template>
      </el-input>


      <el-input v-model="from.password" placeholder="请输入用户密码"
                style="width: 300px" show-password clearable>
        <template #prefix>
          <el-icon class="el-input__icon">
            <Unlock/>
          </el-icon>
        </template>
      </el-input>
      <br>

      <el-input v-model="passwords" placeholder="请再次输入用户密码"
                style="width: 300px" show-password clearable>
        <template #prefix>
          <el-icon class="el-input__icon">
            <lock />
          </el-icon>
        </template>
      </el-input>
      <br>

      <el-radio v-model="from.sex" label="男" style="margin-left: 10px" >男</el-radio>
      <el-radio v-model="from.sex" label="女">女</el-radio>
      <br>

      <el-button type="primary" round style="font-size: 20px;width: 300px;text-align: center;
        margin-top: 20px" @click="login">注册
      </el-button>
    </div>

  </div>
</template>

<script>

import {Avatar, Unlock,ChatDotSquare,Lock} from '@element-plus/icons-vue'
import {ElMessage} from "element-plus";
import request from "@/utils/request";

export default {
  name: "login",
  data() {
    return {
      passwords: "",
      from:{
        username: "",
        password: "",
        sex:"男",
        nickName:"",
      },
      massages: {
        massageDefault: '',//默认灰色
        massageSuccess: 'success',//成功绿色
        massageWarning: 'warning',//警告黄色
        // 红色错误，不使用第二个参数即可
      },//定义顶部弹窗的四种状态
    }
  },
  components: {
    Avatar,
    Unlock,
    ChatDotSquare,
    Lock
  },
  methods:{
    //提示栏函数
    open(massage, type) {

      if (type) {
        ElMessage({
          message: massage,
          type: type,
        })
      }else {
        ElMessage.error(massage)
      }
    },

    login(){
      if (this.passwords===this.from.password){
      request.post("http://localhost:8080/boot/user", this.from)
          .then(_ => {
            //提示弹窗
            this.open("注册成功", this.massages.massageSuccess)
            //清空数据
            this.from = {}
            this.$router.push('/login')
          }).catch(_ => {

        this.open("注册失败，请稍后重试")

      })
    }else {
        this.open("注册失败，密码不一致")
      }
    }
  }

}
</script>

<style scoped>
.shop-login {
  overflow: hidden;
  height: 100vh;
  width: 100%;
  background: #83a4d4;
  background: -webkit-linear-gradient(to right, #b6fbff, #83a4d4);
  background: linear-gradient(to right, #b6fbff, #83a4d4);
}

.shop-login-from {
  overflow: hidden;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 500px;
  height: 400px;
  margin: 5% auto;

  font-size: 34px;
  font-weight: bold;
  text-align: center;
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  padding-top: 100px;

  color: #5e666f;

}


</style>